using System;
using System.Collections.Generic;
using System.Text;
using Zoo.View;
using System.Diagnostics;

namespace Zoo.Controller
{
    public partial class SearchController
    {
        private ISearchView _view;
        private IZooModel _model;
        private Dictionary _dictionary;


        public SearchController(ISearchView searchView,IZooModel zooModel)
        {
            _view = searchView;
            _model = zooModel;
            _dictionary = Dictionary.CreateFromCache(_view.Language, zooModel);

            //PostCondition
            Debug.Assert(_dictionary != null, "Dictionary is Null!");
            Debug.Assert(_model != null, "Search Model is null!");
            Debug.Assert(_view != null, "Search View is null!"); 

            
        }

        public void Initialize()
        {

            if (!_view.IsPostBack)
            {
                _view.LanguageValues = _dictionary.GetListItemValues("LanguageValues");
                _view.GenderValues = _dictionary.GetListItemValues("GenderValues");
                _view.SeekingValues = _dictionary.GetListItemValues("GenderValues");
                _view.UserLanguages.Add(_view.Language);
                _view.Gender = "m";
                _view.Seeking = "f";
            }
            //PostConditions
            Debug.Assert(_view.LanguageValues != null, "RegisterView Languagevalues should not be null!");
            Debug.Assert(_view.GenderValues != null, "RegisterView Gendervalues should not be null");
            Debug.Assert(_view.SeekingValues != null, "RegisterView SeekingValues should not be null!");
        }

        public void OnStartSearch(object sender, EventArgs e)
        {
            _view.Result = _model.FindUsers(
                Utility.ToStringArray(_view.UserLanguages),
                _view.AgeMax,
                _view.AgeMin,
                _view.City,
                _view.Gender,
                _view.CountryID,
                _view.RegionID,
                _view.Seeking);
        }
      


    }
}
